var sig1 = [380,360,320,420,300,400,300,400,340,420,280,400,340,400,320,400,300,420,300,420,300,420,300,3820,700,380,740,360,720,400,720,380,700,380,720,400,700,400,680,400,700,420,680,420,700,360,720,400,340,760,700,400,700,380,360,740,720,380,340,780,700,400,700,380,720,380,340,760,720,380,320,780,720,380,720,380,320,760,720,380,720,400,700,380,720,400,700,400,700,380,340,760,340,780,300,800,300,780,720,360,340,780,320,780,300,800,720,360,340,780,340,740,360,760,300,780,340,760,700,400,340,780,680,400,700,400,340,780,320,760,320,760,340,760,720,380,320,780,720,380,340,760,720,400,300,780,700,400,720,400,320,760,340,760,300];
var sig2 = [340,400,320,400,320,400,320,400,320,400,300,420,300,420,300,420,300,400,320,400,320,400,320,3820,700,400,700,400,680,400,720,400,700,400,680,400,720,400,680,400,720,400,700,400,660,400,740,400,300,800,680,400,720,380,320,760,720,400,300,800,700,400,680,400,720,380,340,760,720,400,300,780,700,400,700,400,320,780,700,380,740,360,700,420,700,400,700,380,700,440,300,760,340,780,320,760,340,740,720,420,300,780,320,780,300,800,720,360,340,780,300];

function test360(sig)
{
  var is360 = x => x>=320 && x<=420;
  if (is360(sig[0]) && is360(sig[1]) && is360(sig[2]) && is360(sig[3]))
  {
    var sp = -1;
    for (var i=0; i<26; i++)
      if (is360(sig[i]/10))
      {
        sp = i;
        break;
      }
    if (sp==-1)
      return;

    var q = sig.map(x => Math.floor(x/360+0.5));
    q.splice(0,sp+1);
//    console.log(q.join(" "));
    var s = [];
    for (var i=0; i<q.length-1; i+=2)
    {
      var bit = q[i] + "" + q[i+1];
      if (bit == "12")
        s.push(0);
      else
      if (bit == "21")
        s.push(1);
      else 
        return;
    }
    console.log(sp + ", " + q.length + ", " + s.length + ", " + s.join(""));
//    console.log(s.join(""));
  }
}

test360(sig1);
test360(sig2);